/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ejemplotiendaweb.controlador;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author franoliva
 */
public class ConexionEJBs {
    private static InitialContext contexto;

    public static void init(String host, int port) {
        try {
            System.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.impl.SerialInitContextFactory");
            System.setProperty("org.omg.CORBA.ORBInitialPort", Integer.toString(port));
            System.setProperty("org.omg.CORBA.ORBInitialHost", host);
            contexto = new InitialContext();
        } catch (NamingException ex) {
            Logger.getLogger(ConexionEJBs.class.getName()).log(Level.SEVERE, null, ex);
            System.exit(0);
            contexto = null;
        }
    }
     public static <T> T getEjb(Class<T> cls) {
        try {
            return (T) contexto.lookup(cls.getName());
        } catch (NamingException ex) {
            Logger.getLogger(ConexionEJBs.class.getName()).log(Level.SEVERE, null, ex);
            System.exit(0);
            return null;
        }
    }



}
